/* This file is part of Gwt--Calendar.
 * Copyright (C) 2011 Vertix Technologies, ltd.
 *
 * Gwt--Calendar is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gwt--Calendar is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Gwt--Calendar.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.vertixtech.gwt.gwtcalendar.server.domain;

import java.util.Date;

import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.validation.constraints.DecimalMin;

/**
 * A parent class of all domains
 * 
 * @author Asaf Shakarchi
 */
public class AbstractDomain {
	@Id
	private Long id = null;

	@DecimalMin("0")
	protected Integer version = 0;

	private Date dateCreated;

	private Date dateUpdated;

	/**
	 * Auto-increment version # whenever persisted
	 */
	@PrePersist
	void onPersist() {
		this.version++;
		setDateUpdated(new Date());
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public Date getDateCreated() {
		return dateCreated;
	}

	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}

	public Date getDateUpdated() {
		return dateUpdated;
	}

	public void setDateUpdated(Date dateUpdated) {
		this.dateUpdated = dateUpdated;
	}
}
